import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = {
  state: {
    userinfo: '',
    storeUpdate: 0, //店铺数据是否有更新
    problemUpdate: 0,//问卷数据是否有更新
    selectQ1: [],
    storeId: '',
    catId: ''
  },
  getters: {
    uInfo: state => state.userinfo
  },
  mutations: {
    setStoreId(_state, data) {
      _state.storeId = data
    },
    setCatId(_state, data) {
      _state.catId = data
    },
    SET_UINFO(_state, data) {
      Vue.set(_state, 'userinfo', data)
    },
    setStoreUpdate(_state, data) {
      _state.storeUpdate = data
    },
    setProblemUpdate(_state, data) {
      _state.problemUpdate = data
    },
    setSelectQ1(_state, data) {
      _state.selectQ1.push(data);
      console.log(_state.selectQ1)
      //uni.setStorage({key:'q1',data:_state.selectQ1})
    },
    deleteSelectQ1(_state, data) {
      _state.selectQ1.splice(_state.selectQ1.findIndex(item => item.goods_id == data.goods_id), 1)
      console.log(_state.selectQ1)
      //uni.setStorage({key:'q1',data:_state.selectQ1})
    }
  }
}

export default new Vuex.Store({
  state: store.state,
  getters: store.getters,
  mutations: store.mutations
})
